﻿namespace SERFLITEMAX20.Viewer
{
    using SERFLITEMAX20;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Xml;

    public class ViewMain
    {
        private int areaid = 0;
        private string areaname = "";
        private int mapid = 0;
        private string mapname = "";
        private Hashtable objects = new Hashtable();
        private ViewObject player = null;
        private ViewObject target = null;
        private string title = "";
        private bool wowactive = true;

        public string GetObjectName(long pGuid)
        {
            if (this.Objects.ContainsKey(pGuid))
            {
                return ((ViewObject) this.Objects[pGuid]).name;
            }
            return "";
        }

        public void InitializeFromXML(string pXML)
        {
            XmlDocument document = new XmlDocument();
            if (pXML.Length != 0)
            {
                document.LoadXml(pXML);
                this.mapid = document.DocumentElement.GetAttribute("mapid", this.mapid);
                this.areaid = document.DocumentElement.GetAttribute("areaid", this.areaid);
                this.wowactive = document.DocumentElement.GetAttribute("wowactive", this.wowactive);
                XmlNodeList list = document.SelectNodes("/Main/object");
                this.player = new ViewObject((XmlElement) document.SelectSingleNode("/Main/player"));
                this.title = this.player.name;
                this.objects[this.Player.guid] = this.Player;
                List<long> list2 = new List<long>();
                list2.Add(this.Player.guid);
            Label_024E:
                foreach (XmlElement element in list)
                {
                    long item = element.GetAttribute("guid").ToLong();
                    list2.Add(item);
                    ViewObject obj2 = null;
                    if (this.objects.Contains(item))
                    {
                        obj2 = (ViewObject) this.objects[item];
                        obj2.Update(element);
                    }
                    else
                    {
                        obj2 = new ViewObject(element);
                    }
                    if (Globals.Filter)
                    {
                        if (Support.filterObjectList.ContainsKey(obj2.key))
                        {
                            if (Support.filterObjectList[obj2.key].filtered)
                            {
                                goto Label_024E;
                            }
                            obj2.special = Support.filterObjectList[obj2.key].special;
                        }
                        else if ((obj2.name.Length != 0) && ((obj2.type == enObjectTypes.GameObject) || (obj2.type == enObjectTypes.Unit)))
                        {
                            Support.filterObjectList.Add(obj2.key, obj2.GetFilterObject());
                        }
                    }
                    this.objects[obj2.guid] = obj2;
                }
                List<long> list3 = new List<long>();
                foreach (ViewObject obj3 in this.objects.Values)
                {
                    if (!list2.Contains(obj3.guid))
                    {
                        list3.Add(obj3.guid);
                    }
                }
                foreach (long num2 in list3)
                {
                    this.objects.Remove(num2);
                }
            }
        }

        public int AreaID
        {
            get
            {
                return this.areaid;
            }
        }

        public string AreaName
        {
            get
            {
                if (Support.areaList.ContainsKey(this.AreaID))
                {
                    return Support.areaList[this.AreaID].name;
                }
                return "";
            }
        }

        public int MapID
        {
            get
            {
                return this.mapid;
            }
        }

        public string MapName
        {
            get
            {
                if (Support.mapList.ContainsKey(this.MapID))
                {
                    return Support.mapList[this.MapID].name;
                }
                return "";
            }
        }

        public Hashtable Objects
        {
            get
            {
                return this.objects;
            }
        }

        public ViewObject Player
        {
            get
            {
                return this.player;
            }
        }

        public ViewObject Target
        {
            get
            {
                return this.target;
            }
        }

        public string Title
        {
            get
            {
                return this.title;
            }
        }

        public bool WoWActive
        {
            get
            {
                return this.wowactive;
            }
        }
    }
}

